package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.mapper.DepartmentMapper;
import cn.wolfcode.crm.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    DepartmentMapper departmentMapper;

    public void delete(Long id) {
        departmentMapper.deleteByPrimaryKey(id);
    }

    public void saveOrUpdate(Department record) {
        if (record.getId() == null) {
            departmentMapper.insert(record);
        } else {
            departmentMapper.updateByPrimaryKey(record);

        }
    }

    public Department get(Long id) {
        return departmentMapper.selectByPrimaryKey(id);
    }

    public Department getByUsername(String s) {
        return departmentMapper.getByUsername(s);
    }

    public List<Department> getAll() {
        return departmentMapper.selectAll();
    }

    public void changeState(Long id) {
        departmentMapper.changeState(id);
    }
}
